<?php

class action_login extends action{
	protected function init(){
		$this->template = 'login.tpl';
	}
	
	public function process($data=null){
		$user = umUser::getInstance();
		
		$formular = umFormular::getInstance();
		
		if($formular->isValidForm()){
			//just then try to login
			try{
				$user->login($formular->getString('loginname'), $formular->getString('password'));
				
				header('Location: ?action=main');
				die('REDIRECT TO <a href="?action=main">MAIN</a>');
			}catch(Exception $e){
				//invalid user...
				$this->smarty->assign('invalid_login', true);
			}
		}
		
		if($formular->isInvalidForm()){
			throw new Exception('INVALID FORM POST', 600);
		}
		
		$user->logout();
		
		$this->assign('formular', $formular);
	}
	
	public function hasAccess(){
		return true;
	}
}
